"""Write Eset

.. helpdoc::
This widget writes an eset signal to a file.  These objects could then be shared as separate objects with other users.  In most cases it might be better to actually export individual objects as tables which would be more generic.  Because of this, this widget will undergo little development until prompting from a user.

"""

"""<widgetXML>
<name>Write eSet</name>
    <name>Display GO Enrichment</name>
    <icon>normalize.png</icon>
    <tags> 
        <tag>Microarray</tag> 
    </tags>
    <summary></summary>
    <author>
        <authorname>Anup Parikh</authorname>
        <authorcontact>anup@red-r.org</authorcontact>
    </author>
</widgetXML>
"""

"""
<name>Display GO Enrichment</name>
<tags>Microarray</tags>
<icon>normalize.png</icon>
"""

from OWRpy import *
import globalData

from libraries.base.signalClasses.RDataFrame import RDataFrame as redRRDataFrame
from libraries.base.signalClasses.RList import RList as redRRList
from libraries.base.signalClasses.RVector import RVector as redRRVector


from libraries.base.qtWidgets.groupBox import groupBox as redRGroupBox
from libraries.base.qtWidgets.commitButton import commitButton as redRCommitButton
from libraries.base.qtWidgets.comboBox import comboBox as redRComboBox
from libraries.base.qtWidgets.radioButtons import radioButtons as redRRadioButtons
from libraries.base.qtWidgets.checkBox import checkBox as redRcheckBox
from libraries.base.qtWidgets.spinBox import spinBox as redRspinBox
from libraries.base.qtWidgets.lineEdit import lineEdit as redRlineEdit
from libraries.base.qtWidgets.graphicsView import graphicsView as redRGraphicsView

class redRGOTree(OWRpy):
    def __init__(self, **kwargs):
        OWRpy.__init__(self, **kwargs)

        self.require_librarys(['Rgraphviz'])
        
        """.. rrsignals::"""
        self.inputs.addInput("testResults", "Test Results", redRRList, self.process)
        
        """.. rrsignals::"""
        self.outputs.addOutput('od1', 'GO Terms Table', redRRDataFrame) #[("data.frame", rdf.RDataFrame)]
        
        """.. rrsignals::"""
        self.outputs.addOutput('od2', 'Test Results', redRRList) #[("data.frame", rdf.RDataFrame)]

        self.ontology = redRComboBox(self.controlArea,label='Ontology')
        self.plotArea = redRGraphicsView(self.controlArea)

        redRCommitButton(self.bottomAreaRight,label='Commit',callback=self.commitFunction)

    def process(self,data):
        self.tests = data.getData()
        self.parentGOData = data.getDataParent()
        
        ontologies = self.R('names(%s)' % self.tests,wantType='list')
        self.ontology.addItems(ontologies)
    
    def commitFunction(self):
        ontology = self.ontology.currentText()
        
        self.plotArea.plot(query='%s$%s, score(%s$%s), useInfo = "all"' % (
        self.parentGOData,ontology, self.tests,ontology), function='showSigOfNodes')
        
        
        